<?php

namespace App\Domain\Menu\Dao;

use App\Domain\Menu\Models\MenuModel;
use App\Http\Models\Permission\PermissionModel;
use Illuminate\Database\Eloquent\Builder;

class MenuDao
{
    public function findByName($name)
    {
        return MenuModel::where('name', $name)->where('state', 1)->first();
    }

    public function findById($id)
    {
        return MenuModel::where('id', $id)->where('state', 1)->first();
    }

    public function del($id)
    {
        return MenuModel::where('id', $id)->update(['state' => '0']);
    }

    /**
     * 添加菜单
     * @param $params
     * @return MenuModel
     */
    public function create($params)
    {
        $params = array_filter_null($params);
        return MenuModel::create($params);
    }

    /**
     * 修改菜单
     * @param MenuModel $model
     * @param $params
     * @return MenuModel
     */
    public function update(MenuModel $model, $params)
    {
        $params = array_filter_null($params);
        $model->fill($params)->save();
        return $model;
    }


}
